<!DOCTYPE html>
<html style="background-color: #F2F2F2">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>后台登录</title>
        <link rel="stylesheet" href="/layui/dist/css/layui.css" />
    </head>
    <body>
        <div class="layui-container" style="margin-top: 100px; width: 400px; padding: 0; background-color: #fff;">
            <h3 style="background-color: #2F4056; padding: 8px 0; text-align: center; font-size: 20px; color: #F0F0F0;">后台登录</h3>
            <div class="layui-form layui-form-pane" style="margin-top: 15px; padding: 15px;">
                <div class="layui-form">

                    <div class="layui-form-item">
                        <label for="admin_name" class="layui-form-label">账号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="admin_name" name="admin_name" placeholder="请输入登录账号" required lay-verify="required" autocomplete="off" class="layui-input" />
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="admin_passwd" class="layui-form-label">密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="admin_passwd" name="admin_passwd" placeholder="请输入密码" required lay-verify="required" autocomplete="off" class="layui-input" />
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" lay-filter="*" lay-submit>立即登录</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>   

                </div>
            </div>
        </div>

        <!-- 你的HTML代码 -->

        <script src="/layui/dist/layui.js"></script>
        <script>
            //一般直接写在一个js文件中
            layui.use(['jquery', 'form', 'layer'], function () {
                var $ = layui.$, form = layui.form, layer = layui.layer;
                form.on('submit(*)', function (data) {
                    $.post('/admin/io/login', data.field, function (result) {
                        result = $.parseJSON(result);
                        if (result.error == 0) {
                            layer.open({
                                content: result.message,
                                icon: 6,
                                yes: function (index, layero) {
                                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                                    window.location.href='/admin/index';
                                }
                            });
                        } else {
                            layer.alert(result.message, {icon: 5});
                        }
                    });
                    return false;
                });
            });
        </script> 
    </body>
</html>